using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;



public class JiQiReng : Singleton<JiQiReng>
{
    public GameObject yanjing_left;
    public GameObject yanjing_right;
    public Sprite normal;
    public Sprite zhayan;

    public AudioSource audioSource;
    public GameObject textshow;
    public TextBreaking text;
    public List<Sound> sounds;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        //Debug.Log((Input.mousePosition-new Vector3(1820,126,0)).normalized*4);
        yanjing_left.transform.localPosition = (Input.mousePosition - new Vector3(1820, 126, 0)).normalized * 4;
        yanjing_right.transform.localPosition = (Input.mousePosition - new Vector3(1820, 126, 0)).normalized * 4;

        if(Input.GetMouseButtonDown(0))
        {
            yanjing_right.GetComponent<Image>().sprite=zhayan;
        }
        else if(Input.GetMouseButtonUp(0))
        {
            yanjing_right.GetComponent<Image>().sprite = normal;
        }
        //hand.transform.localPosition = (Input.mousePosition - new Vector3(1820, 62.5f, 0)).normalized ;
        // hand.transform.localPosition = new Vector3((Input.mousePosition - new Vector3(1820, 62.5f, 0)).normalized.x * 4, (Input.mousePosition - new Vector3(1820, 62.5f, 0)).normalized.y * 4 - 59, 0);
    }


    public void PlayTiShi(AudioClip audioClip,string str)
    {
        StopAllCoroutines();
        {
            StartCoroutine(EventSound(audioClip, str));
           /* if (!MoShiChoice.Instance.isKaoShi)
            {
               
            }*/
        }
      
    }
    IEnumerator EventSound(AudioClip audioClip, string str)
    {
        textshow.SetActive(true);
        audioSource.clip = audioClip;
        text.text = str;
        text.Format();
        audioSource.Play();
        yield return new WaitForSeconds(audioClip.length);
        textshow.SetActive(false);

    }

    public void StopPlay()
    {
        StopAllCoroutines();
        audioSource.Stop();
        textshow.SetActive(false);
    }

    public void PlayMain0()
    {
        PlayTiShi(sounds[0].audioClip, sounds[0].str);
    }

    [Serializable]
    public class Sound
    {
        public AudioClip audioClip;
        public string str;
        
    }
}
